package com.wjy.demo.vo;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Response<T> {

    private static final String FAIL_MSG = "FAIL";
    private static final Integer SERVICE_FAIL_CODE = 500;

    private static final Integer SUCCESS_CODE = 200;
    private static final String SUCCESS_MSG = "SUCCESS";


    private int code;
    private T data;
    private String msg;

    public Response(T data) {
        this.data = data;
    }

    public static <T> Response<T> success(T data) {
        return result(data, SUCCESS_CODE, SUCCESS_MSG);
    }

    public static Response success() {
        return new Response(SUCCESS_CODE, null, SUCCESS_MSG);
    }

    public static Response fail() {
        return new Response(SERVICE_FAIL_CODE, null, FAIL_MSG);
    }

    public static <T> Response<T> fail(T data) {
        return result(data, SERVICE_FAIL_CODE, FAIL_MSG);
    }

    public static <T> Response<T> result(T data, Integer code, String msg) {
        Response<T> response = new Response();
        response.setCode(code);
        response.setData(data);
        response.setMsg(msg);
        return response;
    }


    public static <T> Response<T> fail(Integer code, String msg) {
        Response<T> response = new Response();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }


}
